﻿using System;
using UnityEngine;

public enum LinkType
{
    Invalid = 0,
    Expression = 1, // 表情
    Voice = 2,      // 声音
    Item = 3,       // 物品链接 
    Equip = 4,      // 装备链接 
}

[DisallowMultipleComponent]
/// <summary>
/// 文本超链接功能
/// </summary>
public class UIWord : MonoBehaviour
{
    private UILabel label;
    public Action<int, int> LinkCallback;
    public int MsgIdx { get; private set; }
    public int LinkIdx { get; private set; }
    
    void Awake()
    {
        label = GetComponent<UILabel>();
    }

    void OnClick()
    {
        if (label == null) { return; }
        string url = label.GetUrlAtPosition(UICamera.lastWorldPosition);
        if (string.IsNullOrEmpty(url)) { return; }

        string[] strClip = url.Split('_');
        if (strClip.Length < 2) { return; }
        MsgIdx = int.Parse(strClip[0]);
        LinkIdx = int.Parse(strClip[1]);

        if (LinkCallback != null)
        {
            LinkCallback(MsgIdx, LinkIdx);
        }
    }
}